<?php

class Con_post extends Acan{
	
	public $defaultAct='save';
	function __construct($ainfo=null){
		$this->ctitle = '工具';
		parent::__construct($ainfo=null);
	}
	//
	function Act_save(){
		header('Content-type: text/html; charset=UTF-8');
		header('Access-Control-Allow-Origin: *');
		$frr = array(
			'send'=>array(
				'业务类型'=>'send_type',
				'客户下单时间'=>'send_time',
				'发货人姓名'=>'send_name',
				'邮编'=>'send_code',
				'电话'=>'send_tel',
				'手机'=>'send_phone',
				'发货人地址'=>'send_address'
			),
			'order'=>array(
				'商品名'=>'order_name',
				'商品数量'=>'order_num',
				'物流号'=>'order_wl',
				'运单号'=>'order_code',
				'备注'=>'order_mark'
			),
			'recv'=>array(
				'收货人姓名'=>'recv_name',
				'邮编'=>'recv_code',
				'电话'=>'recv_tel',
				'手机'=>'recv_phone',
				'收货人地址'=>'recv_address'
			)
		);
		$model = Afun_db()->model('acan_post_kuaidi');
		if($_POST['data']){
			$data = json_decode($_POST['data']);
			if(is_object($data)){
				$numi = $numu = 0;
				foreach ($data as $k => $v) {
					$save = array();
					$save['orderid'] = $k;
					foreach ($v as $key => $val) {
						foreach ($val as $f => $str) {
							if($frr[$key][$f]) $save[$frr[$key][$f]]=$str;
						}
					}
					$btsql = '';
					if($save['send_time']){
						$time1 = date('Y-m-d H:i:s',strtotime($save['send_time'])-600);
						$time2 = date('Y-m-d H:i:s',strtotime($save['send_time'])+600);
						$bt = "send_time > '$time1' and send_time < '$time2'";
						$btsql = $bt." and orderid='".$save['orderid']."'";
					}
					if($model->find($btsql)){
						unset($save['orderid']);
						$numu += $model->update($save,$btsql);
					}else{
						$numi += $model->save($save,1);
					}
				}
				$rs['status']=1;
				$rs['msg']=$numi.','.$numu;
				$rs['next']=1;
				if($numi==0){
					$rs['cb']="stop";
				}
			}else{
				$rs['status']=2;
				$rs['msg']='数据错误';
				$rs['next']=2;
			}
			Afun_json($rs);
		}
	}


}

?>